<template>
  <div class="shop" style="margin-left: 20px;margin-right: 20px;">
    <div style="margin-bottom: 20px"><span style="font-weight: bold;font-size: larger">我的店铺</span></div>
    <el-button round @click="dialogFormVisible = true">新增店铺</el-button>
    <div>
      <el-row style="margin: 20px 10px 15px 10px;">
        <el-col :span="4" v-for="(o, index) in shopList" :key="o" :offset="index > 0 ? 2 : 0">
          <el-card :body-style="{ padding: '0px' }">
            <img src="https://img-1315004397.cos.ap-nanjing.myqcloud.com/img/63a2b2c20d361ee6f1465c1f.jpg" class="image">
            <div style="padding: 10px;">
              <span>{{o.shopName}}</span>
              <div class="bottom clearfix">
                <el-button type="text" class="button" @click="enterItem(o.id)">商品管理</el-button>
                <el-button type="text" class="button" @click="enterOrder(o.id)">订单管理</el-button>
              </div>
            </div>
          </el-card>
        </el-col>
      </el-row>
    </div>
    <div class="dialog">
      <el-dialog title="新增店铺" :visible.sync="dialogFormVisible">
        <el-form :model="form">
<!--          <el-form-item label="商家ID" :label-width="formLabelWidth">-->
<!--            <el-input v-model="form.BusinessId" autocomplete="off"></el-input>-->
<!--          </el-form-item>-->
          <el-form-item label="商店名" :label-width="formLabelWidth">
            <el-input v-model="form.shopName" autocomplete="off"></el-input>
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button @click="dialogFormVisible = false">取 消</el-button>
          <el-button type="primary" @click="addShop()">确 定</el-button>
        </div>
      </el-dialog>
    </div>
  </div>
</template>

<script>
import router from "@/router";

export default {
  data() {
    return {
      dialogFormVisible: false,
      form: {
        shopName: '',
      },
      formLabelWidth: '120px',
      shopList:[]
    };
  },
  mounted() {
    // let user=JSON.parse(localStorage.getItem("user"));
    // let token=user.token;
    this.$axios
        .get("http://localhost:2321/business/queryShops",{
              params:{
                businessId:1
              }
            }
            // {
            //   headers:{
            //     token:token
            //   }
            // }
        )
        .then(res => {
          this.shopList=res.data;
        })
        .catch(err => {
          return Promise.reject(err);
        });
  },
  methods:{
    enterItem(id){
      router.push({path:'/itemManager',query:{id:id}});
    },
    enterOrder(id){
      router.push({path:'/orderManager',query:{id:id}});
    },
    addShop(){
      let user=JSON.parse(localStorage.getItem("user"));
      this.$axios
          .get("http://localhost:2321/business/createShopByName",{
                params:{
                  BusinessId:user.id,
                  shopName:this.form.shopName
                }
              }
              // {
              //   headers:{
              //     token:token
              //   }
              // }
          )
          .then(res => {
            this.shopList=res.data;
          })
          .catch(err => {
            return Promise.reject(err);
          });
    }
  }
};
</script>

<style scoped>
.bottom {
  margin-top: 13px;
  line-height: 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.button {
  padding: 0;
  float: right;
}

.image {
  width: 100%;
  display: block;
  height: 150px;
}

.clearfix:before,
.clearfix:after {
  display: table;
  content: "";
}

.clearfix:after {
  clear: both
}

.el-row{
  margin-bottom: 20px;
  display: flex;
  flex-wrap: wrap;
}

.el-row .el-card{
  min-width: 100%;
  height: 100%;
  margin-right: 20px;
  transition: all .5s;
}
</style>
